#include "pch.h"
#include "PostEffect.h"
namespace mini
{

	CPostEffect::CPostEffect()
	{
		D3DXMatrixIdentity(&matrixArray[0]);
		auto pDevice = GEngine->getDevice();
		int nWidth = pDevice->getConfig().screenWidth;
		int nHeight = pDevice->getConfig().screenHeight;
		mpMeshUnit = GEngine->createBillBoard(nWidth, nHeight);
	}

	CPostEffect::~CPostEffect()
	{

	}

	bool CPostEffect::initTarget(int nCount)
	{
		auto pDevice = GEngine->getDevice();
		int nWidth = pDevice->getConfig().screenWidth;
		int nHeight = pDevice->getConfig().screenHeight;
		mpMeshUnit = GEngine->createBillBoard(nWidth, nHeight);
		for (int i = 0; i < nCount; ++i)
		{
			CTexture* pTexture = new CTexture();
			if (nullptr != pTexture)
			{
				if (pTexture->initialiseRenderTexture(nWidth, nHeight, DXGI_FORMAT_R32G32B32A32_FLOAT))
				{
					pTexture->setSampleState(mpMaterialUnit->getSampler(i));
					mpMaterialUnit->setTexture(pTexture, i);
					mTextureArray.push_back(pTexture);
					mpRenderTargetViewArray.push_back(mTextureArray[i]->getRenderTargetView());
				}
				else
				{
					return false;
				}
			}
		}
		return true;
	}

	void CPostEffect::bindMaterialUnit(const std::string& szFile)
	{
		mpMaterialUnit = new CMaterialUnit;
		mpMaterialUnit->setUnitFile(szFile);
		mpMaterialUnit->onInitialise();
		mpMeshUnit->bindMaterial(mpMaterialUnit);
	}

}
